package cn.source.web.controller.gygl;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.source.common.annotation.Log;
import cn.source.common.core.controller.BaseController;
import cn.source.common.core.domain.AjaxResult;
import cn.source.common.enums.BusinessType;
import cn.source.system.domain.Holiday;
import cn.source.system.service.IHolidayService;
import cn.source.common.utils.poi.ExcelUtil;
import cn.source.common.core.page.TableDataInfo;
/**
 * 假期管理Controller
 *
 * @author gygl
 * @date 2023-08-30
 */
@RestController
@RequestMapping("/system/holiday")
public class HolidayController extends BaseController
{
    @Autowired
    private IHolidayService holidayService;
    /**
     * 查询假期管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:holiday:list')")
    @GetMapping("/list")
    public TableDataInfo list(Holiday holiday)
    {
        startPage();
        List<Holiday> list = holidayService.selectHolidayList(holiday);
        return getDataTable(list);
    }
    /**
     * 导出假期管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:holiday:export')")
    @Log(title = "假期管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Holiday holiday)
    {
        List<Holiday> list = holidayService.selectHolidayList(holiday);
        ExcelUtil<Holiday> util = new ExcelUtil<Holiday>(Holiday.class);
        util.exportExcel(response, list, "假期管理数据");
    }
    /**
     * 获取假期管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:holiday:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(holidayService.selectHolidayById(id));
    }
    /**
     * 新增假期管理
     */
    @PreAuthorize("@ss.hasPermi('system:holiday:add')")
    @Log(title = "假期管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Holiday holiday)
    {
        return toAjax(holidayService.insertHoliday(holiday));
    }
    /**
     * 修改假期管理
     */
    @PreAuthorize("@ss.hasPermi('system:holiday:edit')")
    @Log(title = "假期管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Holiday holiday)
    {
        return toAjax(holidayService.updateHoliday(holiday));
    }
    /**
     * 删除假期管理
     */
    @PreAuthorize("@ss.hasPermi('system:holiday:remove')")
    @Log(title = "假期管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(holidayService.deleteHolidayByIds(ids));
    }
}
